package utility;
import java.util.*;

/**
 * This class represents a one-to-one relationship between sets.
 * @author Zachary
 *
 */
public class BidirectionalMap<K,V> {
	private Map<K,V> forward;
	private Map<V,K> backward;
	
	/**
	 * Constructor for BidirectionalMap.
	 */
	public BidirectionalMap(){
		this.forward = new HashMap<K,V>();
		this.backward = new HashMap<V,K>();
	}
	
	/**
	 * Get the object fromt the second set (V) that is mapped to by the key in the first set (K).
	 * @param key
	 * @return
	 */
	public V getFromSecondSet(K key){
		return forward.get(key);
	}
	
	/**
	 * Get the object fromt the first set (K) that is mapped to by the key in the second set (V).
	 * @param key
	 * @return
	 */
	public K getFromFirstSet(V key){
		return backward.get(key);
	}
	
	/**
	 * Put an object into the map.  There will be a one-to-one relationship between the items in
	 * each set.
	 * @param first
	 * @param second
	 */
	public void put(K first, V second){
		forward.put(first, second);
		backward.put(second, first);
	}
}
